package com.isdust.jy.mbank.activity;

import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.isdust.jy.mbank.R;
import com.isdust.jy.mbank.base.BaseActivity;
import com.isdust.jy.mbank.util.DialogHelp;
import com.isdust.zor.core.Habitat;
import com.isdust.zor.core.action.ServerAction;
import com.isdust.zor.core.listener.onTaskCallBackListener;
import com.isdust.zor.core.util.DbUtil;
import com.isdust.zor.core.util.SerializableList;

import java.util.List;

public class HabitatActivity extends BaseActivity {

    @Override
    protected int getLayoutId() {
        return R.layout.activity_creatact;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final DbUtil dbUtil = new DbUtil();
//        public Habitat(String imageID, String title, String clock, int days, int privacy, int catagory, String createdate, String sign) {
        SerializableList<String>list = new SerializableList<>();
        String[]list2 = new String[list.size()];

        list.add("2016-10-3"); //yyyy-M-d
        list.add("2016-10-1");
        list.add("2016-10-9");
        list.add("2016-10-10");
        list.add("2016-10-11");
        list.add("2016-10-12");
        list.toArray(list2);

        final Habitat habitat = new Habitat("12123123","习惯测试","212121",3,1,1,"212121",list2);
        Button button = (Button)findViewById(R.id.phone_sign_in_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dbUtil.insert(habitat);
//                ServerAction.readHabit(null, "", new onTaskCallBackListener<Void>() {
//                    @Override
//                    public void onSuccess() {
//
//                    }
//
//                    @Override
//                    public void onSuccess(List<Habitat> habitats) {
//                        Log.i("habit",habitat.toString());
//                    }
//
//                    @Override
//                    public void onFailure(String error) {
//
//                    }
//                });
                final Dialog dialog = DialogHelp.getWaitDialog(mContext,"请稍后...");
                dialog.show();

                ServerAction.addHabitat(null, "", new onTaskCallBackListener<Void>() {
                    @Override
                    public void onSuccess() {
                        dialog.dismiss();
                        app.getHabitats().add(habitat);
                        setResult(1);
                        finish();
                    }

                    @Override
                    public void onFailure(String error) {
                        dialog.dismiss();
                        setResult(0);
                        finish();
                    }

                    @Override
                    public void onSuccess(List<Habitat> habitats) {

                    }

                });




            }
        });
    }
}
